<template>
  <div>
      <div class="login_top clearfix">
		<a href="index.html" class="login_logo"><img src="../assets/images/logo02.png"></a>	
	</div>

	<div class="login_form_bg">
		<div class="login_form_wrap clearfix">
			<div class="login_banner fl"></div>
			<div class="slogan fl">日夜兼程 · 急速送达</div>
			<div class="login_form fr">
				<div class="login_title clearfix">
					<h1>用户登录</h1>
					<a href="#">立即注册</a>
				</div>
				<div class="form_input">
					<form>
						<input type="text" name="username" class="name_input" placeholder="请输入用户名" v-model="username">
						<div class="user_error">输入错误</div>
						<input type="password" name="pwd" class="pass_input" placeholder="请输入密码" v-model="password">
						<div class="pwd_error">输入错误</div>
						<div class="more_input clearfix">
							<input type="checkbox" name="" v-model="save">
							<label >记住用户名</label>
							<a href="#">忘记密码</a>
						</div>
						<input type="button" name="" value="登录" class="input_submit" @click="login">
					</form>
				</div>
			</div>
		</div>
	</div>

	<MyCertification></MyCertification>
  </div>
    
</template>

<script>
import axios from 'axios'
import mycertification from './common/Certification'
export default {
	components:{
		'MyCertification':mycertification,
	},
	data(){
		return{
			username:localStorage.getItem('username'),
			password:'',
			save:localStorage.getItem('save')
		}
	},methods:{
		login(){
			const fd={
				'username':this.username,
				'password':this.password
			}
			axios.post('http://127.0.0.1:8000/login',fd).then(resp=>{
				console.log(resp.data)
				alert(resp.data.msg)
				if(resp.data.status==200){   //保存 登录状态
					this.$router.push('/')
					sessionStorage.setItem('uid',resp.data.uid)
					sessionStorage.setItem('token',resp.data.token)
					sessionStorage.setItem('username',this.username)
					sessionStorage.setItem('count',resp.data.count)
					if(this.save){    //判断是否要记住用户名
						localStorage.setItem('username',this.username)
						localStorage.setItem('save',this.save)
					}else{
						localStorage.clear()    //不保存 清空 本地存储数据
					}
				}
			}).catch(error=>{
				console.log(error)
			})
		}
	}
}
</script>

<style>

</style>